package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202408;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class leetcode20240826 {
    // 采用递归的方法
    public int getImportance(List<Employee> employees, int id){
        // (id,employee)
        Map<Integer,Employee> map=new HashMap<>();
        for(Employee emp : employees){
            map.put(emp.id,emp);
        }
        return dfs(map,id);
    }

    private int dfs(Map<Integer,Employee> map,int eid){
        Employee emp=map.get(eid);
        int res=emp.importance;
        for(int empId : emp.subordinates){
            res+=dfs(map,empId);
        }
        return res;
    }
}
